<?php
namespace app\mobile\controller;

use think\Controller;
class Course extends Controller
{
	public function cource_module_view()
	{
		return $this->fetch('coursemodule');
	}
	
	public function course_module()
	{
		$result = array('err'=>'1','content' => '');
		 
		$keyword = trim(input('get.keyword'));
		$pageSize = trim(input('get.pageSize'));
		if ($keyword == false || $keyword == null){
			$module_list = db('coursemodules')->field(['id','course_module'])->paginate($pageSize);
		}else {
			$module_list = db('coursemodules')->field(['id','course_module'])->where('course_module','like','%'.$keyword.'%')->paginate($pageSize);
		}
		$result['err'] = '0';
		$result['content'] = '获取教程模块数据成功！';
		$result['data'] = json_encode($module_list->toArray()['data']);
		return $result;
	}
	
	public function course_list_view()
	{
		$course_module_id = trim(input('get.course_module_id'));
		$this->assign('course_module_id',$course_module_id);
		return $this->fetch('course_list');
	}
	
	public function course_list()
	{
		$result = array('err' => '1','content'=>'');
		$keyword = trim(input('get.keyword'));
		$course_module_id = input('get.course_module_id') ? trim(input('get.course_module_id')):0;
		$pageSize = trim(input('get.pageSize'));
		 
		if ($keyword == false || $keyword == null){
			$course_list = db('course')->where('parent_id',$course_module_id)->field(['id','course'])->paginate($pageSize);
		}else{
			$course_list = db('course')->where('parent_id',$course_module_id)->where('course|content','like','%'.$keyword.'%')->field(['id','course'])->paginate($pageSize);
		}
		$result['err'] = '0';
		$result['content'] = '获取教程列表数据成功！';
		$result['data'] = json_encode($course_list->toArray()['data']);
		return $result;
	}
	
	public function course()
	{
		$course_id = trim(input('get.course_id'));
		$course = db('course')->where('id',$course_id)->find();
		$this->assign('course',$course);
		return $this->fetch('course');
	}
}